package tankgame03;

import jdk.internal.org.objectweb.asm.tree.analysis.Value;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.Scanner;

import static java.lang.System.exit;

public class  TankGame  extends JFrame {
	//定义MyPanel
	MyPanel mp = null;
	public static void main(String[] args) throws IOException {
		TankGame tankGame = new TankGame();

	}

	public TankGame() throws IOException {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入选择 1：新游戏 2：继续上局");
		String key = scanner.next();
		mp = new MyPanel(key);
		//将mp放入到thread并启动
		Thread thread = new Thread(mp);
		thread.start();
		this.add(mp);//游戏的绘图区域
		this.setSize(1300,750);
		this.addKeyListener(mp);//监听mp的键盘事件
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				try {
					Recorder.keepRecord();
					exit(0);
				} catch (IOException ex) {
					throw new RuntimeException(ex);
				}
			}
		});
	}
}
